package leetcode.D2000.T1094;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-02-17 13:23:09 星期四
 */

class Solution {
    public boolean carPooling(int[][] trips, int capacity) {
        int[] bus = new int[1001];
        for (int[] trip : trips) {
            bus[trip[1]] += trip[0];
            bus[trip[2]] -= trip[0];
        }
        if (bus[0] > capacity)
            return false;
        for (int i = 1; i < bus.length; i++) {
            bus[i] += bus[i-1];
            if (bus[i] > capacity)
                return false;
        }
        return true;
    }
}